package com.aldobucchi.hierarchy
{
	

	import com.aldobucchi.hierarchy.rel.HierarchicalRelation;
	import com.aldobucchi.hierarchy.rel.HierarchicalRelations;


	public class SimpleHierarchicalConcept implements IHierarchicalConcept
	{
		
		
		private var _str:String;
		public function get str( ):String
		{
			return _str;
		}
		
		
		public function SimpleHierarchicalConcept( str:String )
		{
			_str = str;
		}
		

		public function getHierarchicalRelation( other:IHierarchicalConcept ):HierarchicalRelation
		{

			var o:SimpleHierarchicalConcept = other as SimpleHierarchicalConcept;
			
			if ( o == null )
				return HierarchicalRelations.NONE;
				
			if ( o.str == this.str )
				return HierarchicalRelations.EQUIVALENT;
				
			
			// ex: one is "aaa" and the other "bbb" 
			if ( o.str.charAt( 0 ) != this.str.charAt( 0 ) )
				return HierarchicalRelations.NONE;
				
			
			var diff:int = str.length - o.str.length;
			
			if ( diff == 0 ) // this case is already covered above, but we put it here for carity
				return HierarchicalRelations.EQUIVALENT;		


			var abs:int = Math.abs( diff );
			
					
			if ( diff > 0 )
			{
				if ( abs == 1 )
					return HierarchicalRelations.ABOVE;
				return HierarchicalRelations.HIGHER;
			}
			else
			{
				if ( abs == 1 )
					return HierarchicalRelations.BELOW;
				return HierarchicalRelations.LOWER;
			}		
			
			return null; // will never get here
		
		}
		
	}
}